/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package regras;

import Interfaces.CheckerRule;

/**
 *
 * @author Tainá, Ana Luiza e Amanda
 */
public class RuleRepeatedChar implements CheckerRule {
    private String password;
    public RuleRepeatedChar(String password) {
        this.password = password;
    }
    
    @Override
    public int rule(){
         int repeatedChar=0; 
         int repeatInc = 0;
         int total = 0;
         char[] pwd = password.replaceAll("\\s+", "").toCharArray();
         int size = pwd.length;
         for (int i=0; i<pwd.length; i++){ 
            boolean repChar = false; 
            for (int b=0; b < pwd.length; b++) { 
                 if (pwd[i] == pwd[b] && i != b) { 
                     repChar=true; 
                     repeatInc += Math.abs((double)pwd.length/(b-i)); 
                   } 
            } 
            if (repChar) { 
                    repeatedChar++;
                    if (size-repeatedChar!=0){
                      repeatInc = (int)Math.ceil(repeatInc/(double)(size-repeatedChar));
                    }
                    else{
                        repeatInc = (int)Math.ceil(repeatInc);
                    }
             }
         }
         if (repeatInc>0)
             total -= (int)repeatInc;
         return total;
    }
}
